﻿using Microsoft.AspNetCore.Http;
using SBlogCore.Common.JWTExtend.Helpers;

namespace SBlogCore.Common.JWTExtend.Models
{
    /// <summary>
    /// 令牌
    /// </summary>
    [SkipScan]
    public class TokenModelJwt
    {
        /// <summary>
        /// Id
        /// </summary>
        public long Uid { get; set; }
        /// <summary>
        /// 角色
        /// </summary>
        public string? Role { get; set; }
        /// <summary>
        /// 职能
        /// </summary>
        public string? Work { get; set; }
        /// <summary>
        /// 组织ID
        /// </summary>
        public long? OrgId { get; set; }
        /// <summary>
        /// 公司ID
        /// </summary>
        public long? PlantId { get; set; }

        /// <summary>
        /// 是否为Admin
        /// </summary>
        public bool IsAdmin { get; set; } = false;

    }
    public static class TokenModel
    {
        public static TokenModelJwt? GetTokenUser(this HttpRequest httpRequest)
        {
            var tokenHeader = httpRequest.Headers["Authorization"].ToString().Replace("Bearer ", "");
            if (!string.IsNullOrEmpty(tokenHeader))
            {
                return  JwtHelper.SerializeJwt(tokenHeader);
            }
            return null;
        }
    }
}
